package com.github.shiqiyue.app.common.utils;

import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletRequest;

/***
 * ajax工具类
 * @author Spring
 *
 */
public class AjaxUtils {

    private AjaxUtils() {
    }

    /****
     * 是不是ajax请求
     * @param webRequest
     * @return
     */
    public static boolean isAjaxRequest(WebRequest webRequest) {
        String requestedWith = webRequest.getHeader("X-Requested-With");
        return requestedWith != null && "XMLHttpRequest".equals(requestedWith);
    }

    /***
     * 是不是ajax请求
     * @param request
     * @return
     */
    public static boolean isAjaxRequest(HttpServletRequest request) {
        String requestedWith = request.getHeader("X-Requested-With");
        return requestedWith != null && "XMLHttpRequest".equals(requestedWith);
    }

    /***
     * 是不是ajax上传请求
     * @param webRequest
     * @return
     */
    public static boolean isAjaxUploadRequest(WebRequest webRequest) {
        return webRequest.getParameter("ajaxUpload") != null;
    }

    /***
     * 是不是ajax上传请求
     * @param request
     * @return
     */
    public static boolean isAjaxUploadRequest(HttpServletRequest request) {
        return request.getParameter("ajaxUpload") != null;

    }

}
